/**
 * 
 */
package com.swim.employeeswim.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.employeeswim.entity.EmployeeSwim;
import com.swim.employeeswim.service.EmployeeSwimService;

/**
 * 员工Controller
 * @author 刘军武
 * @version 2021-04-23
 */
@Controller
@RequestMapping(value = "${adminPath}/employeeswim/employeeSwim")
public class EmployeeSwimController extends BaseController {

	@Autowired
	private EmployeeSwimService employeeSwimService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public EmployeeSwim get(String id, boolean isNewRecord) {
		return employeeSwimService.get(id, isNewRecord);
	}
	
	/**
	 * 查询游泳馆员工列表
	 */
	@RequiresPermissions("employeeswim:employeeSwim:view")
	@RequestMapping(value = {"natatoriumList", ""})
	public String natatoriumList(EmployeeSwim employee, Model model) {
		model.addAttribute("employee", employee);
		return "swim/employeeswim/natatoriumEmployeeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("employeeswim:employeeSwim:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<EmployeeSwim> listData(EmployeeSwim employee, HttpServletRequest request, HttpServletResponse response) {
		Page<EmployeeSwim> page = employeeSwimService.findPage(new Page<EmployeeSwim>(request, response), employee); 
		return page;
	}

	/**
	 * 查看游泳馆员工编辑表单
	 */
	@RequiresPermissions("employeeswim:employeeSwim:view")
	@RequestMapping(value = "natatoriumForm")
	public String natatoriumForm(EmployeeSwim employee, Model model) {
		model.addAttribute("employee", employee);
		return "swim/employeeswim/natatoriumEmployeeForm";
	}
	
	/**
	 * 保存员工
	 */
	@RequiresPermissions("employeeswim:employeeSwim:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated EmployeeSwim employeeSwim) {
		//校验登录账号是否存在
		if (!employeeSwimService.checkUserCodeIsExist(employeeSwim.getUserCode())) {
			return renderResult(Global.TRUE, text("系统无此登录账号！请填写正确的登录账号。"));
		}
		employeeSwimService.save(employeeSwim);
		return renderResult(Global.TRUE, text("保存员工成功！"));
	}
	
	/**
	 * 删除员工
	 */
	@RequiresPermissions("employeeswim:employeeSwim:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(EmployeeSwim employeeSwim) {
		employeeSwimService.delete(employeeSwim);
		return renderResult(Global.TRUE, text("删除员工成功！"));
	}
	
}